
#include <stdio.h>
#include <stdlib.h>

#include "../ql/ql.h"
#include "../ql/qlreader.h"
#include "../qlrules/qlrules.h"


// test pack
#include "common.h"
#include "test_list_manip.h"
#include "test_reader.h"
#include "test_eval.h"
#include "test_rules.h"


static void
custom_failure_callback( AllocContext * c, ErrResult err )
{
    printf( "%p ALLOCATOR FAILURE: %d (%s)\n", c, err, get_err_text(err) );

    getchar();
    exit( -1 );
}

static void test()
{
    AllocContext    ac;

    if( QL_OK == init_context(&ac) )
    {
        // apply custom allocator settings if it is needed - this shall be done only ONCE and
        // before performing any allocation what uses this context
        ac.settings.literals_arr_grow_size = 8192;
        ac.failure_callback_p = custom_failure_callback;

        // start working...
        printf( "context initialized\n" );

        //alloc_user_defined_obj( &ac, 65536 ); // this one fails
        //test_list_manip( &ac );
        //test_reader( &ac );
        //test_eval( &ac );
        test_rules1( &ac );
    }
    else
    {
        printf( "can't init ql context\n" );
    }
    
    free_context( &ac );
}

int main()
{
    test();

    ql_dump_mem_leaks();
    printf( "END." );

    //getchar();
    return 0;
}
